<?php
/**
 * Users_Model_Users_Row
 *
 * @version $Id$
 */
class Users_Model_Users_Row extends Lizard_Access_Db_AuthRow
{
    /**
     * Returns the string identifier of the Role
     *
     * @return string
     */
    public function getRoleId()
    {
        return $this->role;
    }

    /**
     * Pre-insert
     *
     * @see Lizard_Db_Table_Row_RowAbstract::_insert()
     */
    protected function _insert()
    {
        if (!$this->firstName && !$this->lastName) {
            $parts = explode('@', $this->email);
            $name = explode('.', $parts['0']);
            $this->firstName = ucfirst($name['0']);
            if (!empty($name['1'])) {
                $this->lastName = ucfirst($name['1']);
            }
        }

        if (!$this->salt) {
            $this->salt = md5(uniqid());
        }

        $this->_update();
    }

    /**
     * Pre-update
     *
     * @see Lizard_Db_Table_Row_RowAbstract::_insert()
     */
    protected function _update()
    {
        if ($this->isDirty('password')) {
            $this->password = $this->encrypt($this->password);
        }
    }

    /**
     * Post-insert
     *
     * @see Zend_Db_Table_Row_Abstract::_postInsert()
     */
    protected function _postInsert()
    {
        $alert = new Lizard_Alerts_Type_Success();
        $alert->message = 'Registration successfull';
        $alert->save();
    }

    /**
     * Post-logout
     *
     * @see Lizard_Access_Db_AuthRow::_postLogout()
     */
    protected function _postLogout()
    {
        $alert = new Lizard_Alerts_Type_Success();
        $alert->message = 'Logout successfull';
        $alert->save();
    }

    /**
     * Post-login
     *
     * @see Lizard_Access_Db_AuthRow::_postLogin()
     */
    protected function _postLogin()
    {
        $alert = new Lizard_Alerts_Type_Success();
        $alert->message = 'Login successfull';
        $alert->save();
    }
}